home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7255 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Will it be auto-deleted?
  5. Date: 21 Feb 1996 23:14:59 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4gg91j$gdc@clarknet.clark.net>
  8. References: <1996Feb20.110314.46035@yogi.urz.unibas.ch>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. Song Jin (song@iso.iso.unibas.ch) wrote:
  16. : I have a question:
  17. : void myfunction(void)
  18. : {
  19. :  double *mypointer = new double[100];
  20. :  .....
  21. : }
  22. : The mypointer and the buffer it pointed will be auto-deleted after returned
  23. : from myfunction, am I right?
  24.  
  25. Absolutely not. Any memory allocated with new has to be deleted 
  26. explicitly. 
  27.  
  28.     delete [] mypointer;
  29.  
  30. Otherwise, once all pointers to it have gone out of scope, it'll just sit
  31. there unreachable until the heap itself is returned to wherever it came
  32. from (if that happens) or garbage collection returns it to the heap (if
  33. your system has garbage collection) or until the machine is rebooted. This
  34. is called a "memory leak". 
  35.  
  36.